package com.jhhc.StormSurgeForecast.AstronomicalTide.ServiceImpl;

import com.jhhc.StormSurgeForecast.AstronomicalTide.Dao.BDMS_FBC_RESULT_PMapper;
import com.jhhc.StormSurgeForecast.AstronomicalTide.Pojo.BDMS_CALCULATESCHEME_M1;
import com.jhhc.StormSurgeForecast.AstronomicalTide.Pojo.BDMS_FBC_RESULT_P;
import com.jhhc.StormSurgeForecast.AstronomicalTide.Service.BDMS_FBC_RESULT_PService;
import com.jhhc.StormSurgeForecast.AstronomicalTide.Util.ReadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

@Service("BDMS_FBC_RESULT_PService")
public class BDMS_FBC_RESULT_PServiceImpl implements BDMS_FBC_RESULT_PService {

    @Autowired
    private BDMS_FBC_RESULT_PMapper pMapper;


    @Override
    public List<BDMS_FBC_RESULT_P> selecTBySchemeId(String schemeId, List<String> stationCodes) {
        return pMapper.selecTBySchemeId(schemeId, stationCodes);
    }

    @Override
    public List<BDMS_FBC_RESULT_P> selecCSCHEMEID(String schemeId) {
        return pMapper.selecCSCHEMEID(schemeId);
    }

    @Override
    public int batchInsert(List<BDMS_FBC_RESULT_P> pList) {
        int num = 0;//insert插入总数量
        int count = 0;//insert插入数量
        // 由于数据库对于插入字段的限制，在这里对批量插入的数据进行分批处理
        int batchCount = 10;//每批commit的个数
        int batchLastIndex = batchCount - 1;// 每批最后一个的下标
        for (int index = 0; index < pList.size() -1;) {
            if(batchLastIndex > pList.size() - 1){
                batchLastIndex = pList.size() - 1;
                count = pMapper.batchInsert(pList.subList(index,batchLastIndex + 1));
                num+=count;
                break;
            }else {
                count = pMapper.batchInsert(pList.subList(index,batchLastIndex + 1));
                index = batchLastIndex + 1;
                batchLastIndex = index + (batchCount - 1);
            }
            num+=count;
        }
        return num;
    }

    @Override
    public int insert(BDMS_FBC_RESULT_P result_p) {
        return  pMapper.insert(result_p);
    }

    @Override
    public List<BDMS_FBC_RESULT_P> queyByCcschemeId(String cschemeId) {
        return pMapper.queyByCcschemeId(cschemeId);
    }

    @Override
    public BDMS_FBC_RESULT_P selecBySchemeId(String schemeId, String stationCode, int typeId) {
        return pMapper.selecBySchemeId(schemeId, stationCode, typeId);
    }

    @Override
    public int updateDtvaluesInt(String dtvalues, String stcd,String schemeId) {
        return pMapper.updateDtvaluesInt(dtvalues,stcd,schemeId);
    }

    @Override
    public int update(BDMS_FBC_RESULT_P result_p) {
        return  pMapper.update(result_p);
    }


    @Override
    public int deleteByCschemeId(String cschemeId) {
        return pMapper.deleteByCschemeId(cschemeId);
    }

}
